cmake_minimum_required(VERSION 3.5)
project(slam_rviz)

if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
endif()

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rviz_common REQUIRED)
find_package(pluginlib REQUIRED)
find_package(slam_ros REQUIRED)
find_package(slam_ros_msgs REQUIRED)
find_package(slam REQUIRED)
find_package(Boost REQUIRED COMPONENTS system iostreams)
find_package(absl REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(pcl_conversions REQUIRED)

# Qt5 setup
find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
set(QT_LIBRARIES Qt5::Core Qt5::Widgets)

set(CMAKE_AUTOMOC ON)
add_definitions(-DQT_NO_KEYWORDS)

include_directories(
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${slam_ros_INCLUDE_DIRS}
  ${slam_ros_msgs_INCLUDE_DIRS}
  ${nav_msgs_INCLUDE_DIRS}
  #${PCL_INCLUDE_DIRS}
  ${pcl_conversions_INCLUDE_DIRS}
)

# Source files
file(GLOB_RECURSE ALL_SRCS "slam_rviz/*.cc" "slam_rviz/*.h")
list(FILTER ALL_SRCS EXCLUDE REGEX ".*_main\\.cc$")

# Library target
add_library(${PROJECT_NAME} ${ALL_SRCS})
target_compile_definitions(${PROJECT_NAME} PRIVATE "QT_NO_KEYWORDS")

# Include directories
target_include_directories(${PROJECT_NAME}
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
    ${EIGEN3_INCLUDE_DIR}
    ${Boost_INCLUDE_DIRS}
    ${OPENSSL_INCLUDE_DIRS}
)

target_link_libraries(${PROJECT_NAME} PUBLIC
  ${QT_LIBRARIES}
  ${Boost_LIBRARIES}
  ${OPENSSL_LIBRARIES}
  slam
  rviz_common::rviz_common
  pluginlib::pluginlib
  rclcpp::rclcpp
  slam_ros
  slam_ros_msgs
)

ament_export_dependencies(
  rclcpp
  rviz_common
  pluginlib
  slam_ros
  slam_ros_msgs
)

# Install targets
install(TARGETS ${PROJECT_NAME}
  EXPORT export_${PROJECT_NAME}
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
  INCLUDES DESTINATION include
)

install(FILES rviz_plugin_description.xml
  DESTINATION share/${PROJECT_NAME}
)

install(DIRECTORY ogre_media
  DESTINATION share/${PROJECT_NAME}
)

install(
  DIRECTORY slam_rviz
  DESTINATION include
  FILES_MATCHING PATTERN "*.h"
)

# Export targets
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies(rclcpp rviz_common pluginlib slam_ros slam_ros_msgs)

ament_package()